package com.itheima03.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

/**
 * @Author TDD
 * @Date 2021/6/27 19:11
 * @Version 1.0
 */
public class MyBatisConfig {
    public MyBatisConfig() {
    }
     public static SqlSessionFactory sqlSessionFactory ;

    static {
        try {
            sqlSessionFactory= new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("MyBatisConfig1.xml"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession(true);
    }
}
